<?php
class FormObj
{
	private $post = array(); //Array with $_POST data
	private $get = array(); //Array with $_GET data
	
	public function __construct()
	{
		if(!empty($_POST))
		{
			$this->getArray('POST'); //Get $_POST array
		}

		if(!empty($_GET))
		{
			$this->getArray('GET'); //Get $_GET array
		}
	}

	/*
	*Get clear array with request data
	*
	*@param method: request method
	*set $this->post; $this->get
	*/
	private function getArray($method)
	{
		switch($method)
		{
			case 'GET':
				foreach($_GET as $key=>$value)
				{
					$key  = $this->clearData($key);
					$value = $this->clearData($value);
					if(!$value)
					{
						$value = '';	
					}
					if(!$key)
					{
						$key = '';
					}
					$this->get[$key] = $value;
				}
				break;

			case 'POST':
					
				foreach($_POST as $key=>$value)
				{

					$key  = $this->clearData($key);
					$value = $this->clearData($value);
					if(!$value)
					{
						$value = '';	
					}
					if(!$key)
					{
						$key = '';
					}
					$this->post[$key] = $value;
				}
				break;
		}
	}

	/*
	*return array with $_POST data
	*/	
	public function getPost()
	{
		if(isset($this->post) && is_array($this->post) && !empty($this->post))
		{
			return $this->post;
		}
		else
		{
			return false;
		}
	}

	/*
	*return array with $_GET data
	*/	
	public function getGet()
	{
		if(isset($this->get) && is_array($this->get) && !empty($this->get))
		{
			return $this->get;
		}
		else
		{
			return false;
		}
	}
	
	private function clearData($data)
	{
		if(is_string($data))
		{
			$data = trim(strip_tags($data));
		}	
		if($data)
		{
			return $data;
		}
		else
		{
			return false;
		}
		
	}

}
